import { createApp } from 'vue';
import VueRouter from 'vue-router';
import store from 'vuex'
import Index from '@/views/Index';
import Home from '@/views/home/Home';
import Category from '@/views/category/Category';
import Article from '@/views/article/Article';
import Bcategory from '@/views/bcategory/Bcategory';
import Business from '@/views/business/Business';

createApp().use(VueRouter)

const routes=[
    {
        path: '/',
        component: Index,
        redirect: '/home',
        children: [
            {
                path: '/home',
                name: 'home',
                component: Home,
                meta: {
                    title: '首页'
                }
            },
            {
                path: '/category/:id',
                name: 'category',
                component: Category,
                meta:{
                    title: '文章分类'
                }
            },
            {
                path: '/article/:id',
                name: 'article',
                component: Article,
                meta:{
                    title: '文章'
                }
            },
            {
                path: '/bcategory/:id',
                name: 'bcategory',
                component: Bcategory,
                meta:{
                    title: '业务分类'
                }
            },
            {
                path: '/business/:id',
                name: 'business',
                component: Business,
                meta:{
                    title: '业务'
                }
            }
        ]
    }
]

const router=new VueRouter({
    mode:'history',
    base:process.env.BASE_URL,
    routes:routes
})
// 挂在路由守卫
router.beforeEach((to,from,next)=>{
    if(to.meta.title){
        if(store.state.siteInfo.webTitleSuffix){
            document.title=to.meta.title+store.state.siteInfo.webTitleSuffix
        }else{
            document.title=to.meta.title
        }
    }
    next()
})

export default router